package com.wit.example.util;



import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


public class CSVWriter {

    /**
     * Writes a formatted string into a CSV file.
     *
     * @param internalStorageDir  the internalStorageDir
     * @param dataStr  the string data in format "Left X:8 Y:-22 Z:-21"
     */
    public static void writeStringToCsv(File internalStorageDir, String dataStr, String type) {
        // Check if external storage is available for read and write
        String filename = type + "_data.csv";
        File csvFile = new File(internalStorageDir, filename);

        // Get current timestamp
        long timestamp = System.currentTimeMillis();

        try (FileWriter writer = new FileWriter(csvFile, true)) {
            // Write the processed data to the CSV file
            writer.append(String.valueOf(timestamp));
            writer.append(" ");
            writer.append(dataStr);
            writer.append("\n");
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
